﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Media;

namespace WpfChart.DataStruct
{
    public class StockData:INotifyPropertyChanged
    {
        private double _open;
        public double Open
        {
            get { return _open; }
            set
            {
                _open = value;
                OnPropertyChanged("Open");
            }
        }

        private double _close;
        public double Close {
            get { return _close; }
            set
            {
                _close = value;
                OnPropertyChanged("Close");
            }
        }

        private double _maxPrice;
        public double MaxPrcie { 
            get { return _maxPrice; }
            set
            {
                _maxPrice = value;
                OnPropertyChanged("MaxPrcie");
            }
        }

        private double _minPrice;
        public double MinPrice
        {
            get { return _minPrice; }
            set
            {
                _minPrice = value;
                OnPropertyChanged("MinPrice");
            }
        }

        private string _time;
        public string Time
        {
            get { return _time; }
            set
            {
                _time = value;
                OnPropertyChanged("Time");
            }
        }

        private int _postionCnt;
        public int PostionCnt
        {
            get { return _postionCnt; }
            set {
                _postionCnt = value;
                OnPropertyChanged("PostionCnt");
            }
        }

        private string _showTime;
        public string ShowTime
        {
            get { return _showTime; }
            set
            {
                _showTime = value;
                OnPropertyChanged("ShowTime");
            }
        }

        public double[] YScaleValues
        {
            get {
                return new double[] { Open, Close, MaxPrcie, MinPrice };     
            }
        }

        public Brush LineColor
        {
            get {

                if (Close > Open)
                {
                    return new SolidColorBrush(Colors.Tomato);
                }
                else if (Close < Open)
                {
                    return new SolidColorBrush(Colors.Green);
                }
                return new SolidColorBrush(Colors.Tomato);
            }
            set {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("YValues"));
            }
        }


        public StockData(double open, double close, double max, double min, string time, int postionCnt)
        {
            this.Open = open;
            this.Close = close;
            this.MaxPrcie = max;
            this.MinPrice = min;
            this.Time = time;
            this.PostionCnt = postionCnt;
            this.ShowTime = time;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string info)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(info));
            }
        }


    }
}
